package com.jyy.prefabricated.service;

import com.jyy.prefabricated.entity.Option;
import com.jyy.prefabricated.exception.CustomException;
import com.jyy.prefabricated.mapper.OptionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @version 1.0.0
 * @author: zjj
 */

@Service
public class OptionService {

    @Autowired
    private OptionMapper optionMapper;


    /**
     * 新增
     * @param option
     * @return
     */
    public Integer insert(Option option){
        optionMapper.insert(option);
        return option.getId();
    }

    /**
     * 更新
     * @param option
     * @return
     */
    public int update(Option option){
        if(option.getId() == null){
            throw new CustomException("参数id不能为空");
        }
        return optionMapper.updateByPrimaryKeySelective(option);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public int delete(Integer id){
        return optionMapper.deleteByPrimaryKey(id);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public Option selectById(Integer id){
        return optionMapper.selectByPrimaryKey(id);
    }
}
